package com.xin.vip.pattern.prototype.simple;

import java.util.ArrayList;
import java.util.List;

public class PrototypeTest {

    public static void main(String[] args) {
        ConcretePrototypeA concretePrototype = new ConcretePrototypeA();
        concretePrototype.setAge(18);
        concretePrototype.setName("prototype");
        List hobbies = new ArrayList<String>();
        hobbies.add("跑步1");
        hobbies.add("学习2");
        concretePrototype.setHobbies(hobbies);
        System.out.println(concretePrototype);

        System.out.println("-----------------------");

        Client client = new  Client(concretePrototype);
        ConcretePrototypeA concretePrototype2 = (ConcretePrototypeA)client.startClone(concretePrototype);
        List hobbies2 = new ArrayList<String>();

        hobbies2.addAll(concretePrototype2.getHobbies());
        hobbies2.add("跑步3");
        hobbies2.add("学习4");
        concretePrototype2.setHobbies(concretePrototype2.getHobbies());
        concretePrototype2.setHobbies(hobbies2);
        System.out.println(concretePrototype2.getHobbies());
        System.out.println(concretePrototype2);

        System.out.println("克隆对象中的引用类型地址值：" + concretePrototype2.getHobbies());
        System.out.println("原对象中的引用类型地址值：" + concretePrototype.getHobbies());
        System.out.println("对象地址比较："+(concretePrototype2.getHobbies() == concretePrototype.getHobbies()));




    }



}
